<?php

function list_ttd(){
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Uraian'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Bidang'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Penandatangan'=>array('style'=>'border-bottom:2px solid;width:30%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:30%'),  
	);
	$query = "SELECT * FROM konfigurasi_ttd ORDER BY kolom_id ASC";	
	$result = my_query($query);
	$i=0;
	$row=array();
	while($ey = my_fetch_array($result )){
		$i++;
		$row[] = array(
			'#'=>position_text_align($i,'center'),
			'uraian'=>  $ey['kolom_label'] ,
			'bidang'=>  $ey['bidang'] ,
			'ttd'=>  $ey['ttd'] ,
			'jabatan'=>  $ey['jabatan'] ,
		);
	}	
	$datas = table_rows($row); 
	return table_builder($header , $datas ,  15 ,false  );
}

function form_ttd(){

	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'Uraian'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Bidang'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Penandatangan'=>array('style'=>'border-bottom:2px solid;width:30%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:30%'),  
	);
	$query = "SELECT * FROM konfigurasi_ttd ORDER BY kolom_id ASC";	
	$result = my_query($query);
	$i=0;
	$row=array();
	while($ey = my_fetch_array($result )){
		$i++;
		$temp = array(
			'name'=>'bid_'.$ey['kolom_id'],
			'value'=>isset($_POST['bid_'.$ey['kolom_id']]) ? $_POST['bid_'.$ey['kolom_id']]: $ey['bidang'],
			'size'=>15
		);
		$form_temp1 = form_dynamic($temp);
		$temp = array(
			'name'=>'ttd_'.$ey['kolom_id'],
			'value'=>isset($_POST['ttd_'.$ey['kolom_id']]) ? $_POST['ttd_'.$ey['kolom_id']]: $ey['ttd'],
			'size'=>30
		);
		$form_temp2 = form_dynamic($temp);
		$temp = array(
			'name'=>'jbt_'.$ey['kolom_id'],
			'value'=>isset($_POST['jbt_'.$ey['kolom_id']]) ? $_POST['jbt_'.$ey['kolom_id']]: $ey['jabatan'],
			'size'=>30
		);
		$form_temp3 = form_dynamic($temp);		
		$row[] = array(
			'#'=>position_text_align($i,'center'),
			'uraian'=>  $ey['kolom_label'] ,
			'bid'=>  $form_temp1 ,
			'ttd'=>  $form_temp2 ,
			'jabatan'=>  $form_temp3 ,
		);
	}	
	$datas = table_rows($row);
	return '<form method="POST" name="formDataSubmit">'.table_builder($header , $datas ,  5 , false ).'</form>';
}

function validasi_ttd(){
	$errsubmit = false;
	$err = array();
	$query = "SELECT * FROM konfigurasi_ttd ORDER BY kolom_id ASC";	
	$result = my_query($query);
	while( $row = my_fetch_array($result) ){
	}
	if( $errsubmit){
		return $err;
	}
	
	return $errsubmit;
}

function submit_ttd(){
	$query = "SELECT * FROM konfigurasi_ttd ORDER BY kolom_id ASC";
	$result = my_query($query);
	$datas = array(); 
	while($te = my_fetch_array($result) ){ 
		$datas = array(
			'bidang'=>my_type_data_str($_POST['bid_'.$te['kolom_id']]),
			'ttd'=>my_type_data_str($_POST['ttd_'.$te['kolom_id']]),
			'jabatan'=>my_type_data_str($_POST['jbt_'.$te['kolom_id']]),
		);	 	
		my_update_record( 'konfigurasi_ttd', 'kolom_id',$te['kolom_id'],$datas);
	}
	return true;
}
